/*
 * www.yiji.com Inc.
 * Copyright (c) 2013 All Rights Reserved.
 */
package com.yiji.fintech.musfinance.base.enums;

import com.google.common.collect.Maps;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/*
 * 修订记录：
 * zeyong 2014-3-27 下午6:17:40 创建
 */

/**
 * <b>支付类型枚举值</b> <br>
 * 1.<code>DEPOSIT</code>:充值.<br>
 * 2.<code>WITHDRAW</code>:提现.<br>
 * 3.<code>DEPOSIT_BACK</code>:充退.<br>
 * 5.<code>SIGN</code>:签约.<br>
 * 7.<code>QUERY</code>:查询.<br>
 *
 * @author zeyong
 */

public enum TransactionTypeEnum {

    /**
     * 充值
     */
    DEPOSIT("1", "DEPOSIT", "充值"),

    /**
     * 提现
     */
    WITHDRAW("2", "WITHDRAW", "提现"),

    /**
     * 充退
     */
    DEPOSIT_BACK("3", "DEPOSIT_BACK", "充退"),

    /**
     * 签约
     */
    SIGN("5", "SIGN", "签约"),

    /**
     * 验证
     */
    VERIFY("6", "VERIFY", "验证"),


    UNSIGN("8","UNSIGN","解约"),

    /**
     * 查询
     */
    QUERY("9", "QUERY", "查询");

    /**
     * 数字编号
     */
    private final String number;

    /**
     * 英文编码
     */
    private final String code;

    /**
     * 中文描述
     */
    private final String message;

    /**
     * 构造一个<code>InstChannelApiBizCodeEnum</code>枚举对象
     *
     * @param number  : 数字编号
     * @param code    : 英文编码
     * @param message : 中文描述
     */
    private TransactionTypeEnum(String number, String code, String message) {
        this.number = number;
        this.code = code;
        this.message = message;
    }

    /**
     * @return Returns the 英文编码.
     */
    public String getCode() {
        return code;
    }

    /**
     * @return Returns the 英文编码.
     */
    public String code() {
        return code;
    }

    /**
     * @return Returns the 中文描述.
     */
    public String getMessage() {
        return message;
    }

    /**
     * @return Returns the 中文描述.
     */
    public String message() {
        return message;
    }

    /**
     * @return Returns the 数字编号.
     */
    public String getNumber() {
        return number;
    }

    /**
     * @return Returns the 数字编号.
     */
    public String number() {
        return number;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return InstChannelApiBizCodeEnum
     */
    public static TransactionTypeEnum getByCode(String code) {
        for (TransactionTypeEnum _enum : values()) {
            if (_enum.getCode().equals(code)) {
                return _enum;
            }
        }
        return null;
    }

    /**
     * 通过枚举<code>number</code>获得枚举
     *
     * @param number
     * @return InstChannelApiBizCodeEnum
     */
    public static TransactionTypeEnum getByNumber(String number) {
        for (TransactionTypeEnum _enum : values()) {
            if (_enum.getNumber().equals(number)) {
                return _enum;
            }
        }
        return null;
    }

    /**
     * 获取全部枚举
     *
     * @return List<InstChannelApiBizCodeEnum>
     */
    public static List<TransactionTypeEnum> getAllEnum() {
        List<TransactionTypeEnum> list = new ArrayList<TransactionTypeEnum>();
        for (TransactionTypeEnum _enum : values()) {
            list.add(_enum);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public static List<String> getAllEnumCode() {
        List<String> list = new ArrayList<String>();
        for (TransactionTypeEnum _enum : values()) {
            list.add(_enum.code());
        }
        return list;
    }

    /**
     * 判断给定的枚举，是否在列表中
     *
     * @param values 列表
     * @return
     */
    public boolean isInList(TransactionTypeEnum... values) {
        for (TransactionTypeEnum e : values) {
            if (this == e) {
                return true;
            }
        }
        return false;
    }

    public static Map<String, String> mapping() {
        Map<String, String> map = Maps.newLinkedHashMap();
        for (TransactionTypeEnum type : values()) {
            map.put(type.getCode(), type.getMessage());
        }
        return map;
    }

    /**
     *
     * @param msg
     * @return SwichStatusEnum
     */
    public static TransactionTypeEnum getByMsg(String msg) throws Exception{
        TransactionTypeEnum transactionTypeEnume = null;
        for (TransactionTypeEnum _enum : values()) {
            if (_enum.getMessage().equals(msg)) {
                transactionTypeEnume =  _enum;
            }
        }
        if(transactionTypeEnume == null){
            throw new Exception("交易类型不能为空");
        }
        return transactionTypeEnume;
    }
}